<?php
	require("header.php");
?>
<?php
	//如果不是qc提示无法访问此网页
	if($userType !== "qc") { 
		header("location: accesserror.php");
	}
?>
<div id="content">
  <div id="content-header">
    <div id="breadcrumb"> <span><i class="icon-home"></i> 问题单管理</span></div>
  </div>

  <div class="container-fluid">

    <div class="row-fluid">
      <div class="widget-box">
        <div class="widget-title bg_lg"><span class="icon"><i class="icon-th-list"></i></span>
          <h5>创建问题单</h5>
        </div>
        <div class="widget-content nopadding">
            <form class="form-horizontal" method="post" action="docreateproblem.php">
            <?php
              	if(isset($_GET["result"])) { 
              		$result = $_GET["result"];
              		echo '<br>';
              		if($result !== "success") { 
              			echo '<div class="alert alert-error">';
              			echo '<strong>创建失败!</strong> ' . $result . '</div>';
              		} else { 
              			echo '<div class="alert alert-success">';
              			echo '<strong>创建成功!</strong>问题单编号为'.$_GET["id"].'</div>';
              		}
              	}
              ?>
              <div class="center control-group">
                <label class="control-label">项目</label>
                <div class="controls">
                  <input type="text" name="project">
                </div>
              </div>
              <div class="center control-group">
                <label class="control-label">执行日期</label>
                <div class="controls">
                  <input id="createtime" type="text" name="startTime">
                </div>
              </div>
              <div class="center control-group">
                <label class="control-label">城市</label>
                <div class="controls">
                  <input type="text" name="city">
                </div>
              </div>
              <div class="center control-group">
                <label class="control-label">店铺编号</label>
                <div class="controls">
                  <input type="text" name="storeNum">
                </div>
              </div>
              <div class="center control-group">
                <label class="control-label">店铺名</label>
                <div class="controls">
                  <input type="text" name="storeName">
                </div>
              </div>
              <div class="center control-group">
                <label class="control-label">店铺地址</label>
                <div class="controls">
                  <input type="text" name="storeAddress">
                </div>
              </div>
              <div class="center control-group">
                <label class="control-label">问卷题目号码</label>
                <div class="controls">
                  <input type="text" name="questionNum">
                </div>
              </div>
              <div class="center control-group">
                <label class="control-label">督导</label>
                <div class="controls">
                  <div class="well well-small">
                    <ul id="supervisors">
					</ul>
				  </div>
                  <span class="btn btn-info" data-toggle="modal" data-target="#selectSupervisor">选择督导</span>
                </div>
              </div>
              <div class="center control-group">
                <label class="control-label">执行人员</label>
                <div class="controls">
                  	<div class="well well-small">
                    <ul id="inspecters">
					</ul>
				  </div>
          		   <span class="btn btn-info" data-toggle="modal" data-target="#selectInspecter">选择执行人员</span>
                </div>
              </div>
              <div class="center form-actions">
                <input type="submit" value="创建" class="btn btn-large btn-success">
              </div>
			  <select id="post-supervisors" name="supervisors[]" style="display:none" multiple></select>
			  <select id="post-inspecters" name="inspecters[]" style="display:none" multiple></select>
            </form>
          </div>
      </div>
    </div>
    <hr/>         
</div>

<!-- 选择督导 -->
<div class="modal fade" id="selectSupervisor" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"></button>
        <h4 class="modal-title" id="myModalLabel">选择督导</h4>
      </div>
      <div class="modal-body">
        <div id="all-supervisors"class="text-center row">
        	<?php
	        	$connect = mysql_connect("localhost","root","yxs147789");
				if ($connect) {
				  	mysql_select_db("inspectdb", $connect);
				  	mysql_query("set names 'utf8'");
				  	$querystr = "SELECT user_name FROM users WHERE type='supervisor'";
				  	$result = mysql_query($querystr);
				  	while($row = mysql_fetch_array($result)) {
					   echo '<span select="false" class="span1 select-item">' . $row["user_name"] . '</span>';
					}
				}
				mysql_close($connect);
        	?>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" select-target="supervisors" data-dismiss="modal" class="do-select btn btn-primary">确定</button>
      </div>
    </div>
  </div>
</div>
<!-- 选择执行人员 -->
<div class="modal fade" id="selectInspecter" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"></button>
        <h4 class="modal-title" id="myModalLabel">选择执行人员</h4>
      </div>
      <div class="modal-body">
      	<div id="all-inspecters" class="text-center row">
      		<?php
	        	$connect = mysql_connect("localhost","root","yxs147789");
				if ($connect) {
				  	mysql_select_db("inspectdb", $connect);
				  	mysql_query("set names 'utf8'");
				  	$querystr = "SELECT user_name FROM users WHERE type='inspecter'";
				  	$result = mysql_query($querystr);
				  	while($row = mysql_fetch_array($result)) {
					   echo '<span select="false" class="span1 select-item">' . $row["user_name"] . '</span>';
					}
				}
				mysql_close($connect);
        	?>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" select-target="inspecters" data-dismiss="modal" class="do-select btn btn-primary">确定</button>
      </div>
    </div>
  </div>
</div>
<?php
	require("footer.php");
?>
<script src="js/bootstrap-datepicker.js"></script> 
<script>
	$(document).ready(function() { 
		$('#createtime').datepicker({
		  format: 'yyyy-mm-dd',
	        weekStart: 1,
	        autoclose: true,
    		todayBtn: 'linked'
		 });
		$('.select-item').click(function() { 
			var $this = $(this);
			if ($this.attr("select") === "false") {
				$this.css({
					'background': '#1874CD',
					'color': '#fff'
				});
				$this.attr("select", "true");
			} else { 
				$this.css({
					'background': '#fff',
					'color': '#000'
				});
				$this.attr("select", "false");
			}
		});
		$('.do-select').click(function() { 
			console.log()
			var $this = $(this);
			var target = $this.attr('select-target');
			var $all = $('#all-' + target);
			var $select = $('#' + target);
			var $post = $('#post-' + target);
			var tempArray = [];
			$all.children().each(function() { 
				var $one = $(this);
				if($one.attr('select') === 'true')
				tempArray.push($one.html());
			});
			$select.empty();
			$post.empty();
			for(var i = 0; i < tempArray.length; i++) { 
				$select.append('<li>' + tempArray[i] + '</li>');
				$post.append('<option selected="true">' + tempArray[i] + '</option>');
			}
		});
	});
</script>